import { resolve } from '@/appUtils/path'
import { process } from '@/appUtils/process'
import { BrowserWindow, session } from '@electron/remote'

const extensionPath =
    import.meta.env.MODE === 'development'
        ? resolve('./public/selector-extension')
        : resolve(process.env.APP_ROOT || '', './dist/renderer/selector-extension')

// window.onSelectionChanged = () => {
//     console.log(getComputedStyle($0).backgroundImage)
// }

let installed = false

const install = () => {
    if (installed) return
    installed = true

    session.defaultSession.extensions
        .loadExtension(extensionPath)
        .then((res) => {
            console.log('extention loaded', res.name)
            // console.log(res)
            const win = new BrowserWindow({ show: false })
            win.loadURL(res.url + '/hello.html')
        })
        .catch((err) => {
            console.log('extention load error', err)
        })
}

install()
